package com.lc.tgxm.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lc.tgxm.R;
import com.lc.tgxm.model.BannerMod;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;


/**
 * Girdview Adapter
 * Created by Lei on 2016/06/17.
 */
public class GvAdapter extends ArrayAdapter<BannerMod> {
    private LayoutInflater layoutInflater;

    public GvAdapter(Context context, List<BannerMod> objects) {
        super(context, 0, objects);
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        final BannerMod bannerMod = getItem(position);
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.item_gv, null);
            ScaleScreenHelperFactory.getInstance().loadViewGroup((ViewGroup) convertView);
            viewHolder = new ViewHolder();
            viewHolder.tvTitle = (TextView) convertView.findViewById(R.id.tv_title);
            viewHolder.ivTop = (ImageView) convertView.findViewById(R.id.iv_top);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tvTitle.setText(bannerMod.title);
        viewHolder.ivTop.setImageResource(bannerMod.resid);

        return convertView;
    }

    private class ViewHolder {
        TextView tvTitle;
        ImageView ivTop;
    }

}